'use strict';
const db = uniCloud.database() // 获取数据库实例
const collection = db.collection('houselist') // 创建表的引用
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	const {pageSize, pageNum} = event
	
	const start = pageSize * (pageNum - 1)
	//在云函数里面获取云数据库中的内容
	const data = await collection.skip(start).limit(pageSize).get() // {data: []}
	const total = await collection.count() // {total: 12}
	console.log(data)
	//返回数据给客户端
	return {
		code: 200,
		data: {
			list: data.data,
			total: total.total 
		}
	}
};
